class Settings():
    """
    存储《外星人入侵》的所有设置的类
    """
    # 系统默认设置
    screen = {
        "width": 1200,
        "height": 600,
        "bg_color": (230, 230, 230)
    }
    ship = {
        "speed": 1.5,
        "limit": 3
    }
    bullet = {
        "width": 3,
        "height": 15,
        "bg_color": (60, 60, 60),
        "speed": 3,
        "allowed": 50
    }
    alien = {
        "speed": 1,
        "drop_speed": 10,
        # fleet_direction为1表示向右移，为-1表示向左移
        "fleet_direction": 1,
        # 分值的提高速度
        "score_scale": 1.5,
        # 初始分值
        "points": 50
    }
    game = {
        # 游戏速度值
        "speedup_scale": 1.1
    }

    def __init__(self, **kwargs):
        """
        初始化游戏设置
        """

        # 同步用户自定义的设置
        for k, v in kwargs.items():
            if k == "screen":
                for attr_k, attr_v in v.items():
                    self.screen[attr_k] = attr_v
            elif k == "ship":
                for attr_k, attr_v in v.items():
                    self.ship[attr_k] = attr_v
            elif k == "bullet":
                for attr_k, attr_v in v.items():
                    self.bullet[attr_k] = attr_v
            elif k == "alien":
                for attr_k, attr_v in v.items():
                    self.alien[attr_k] = attr_v
            elif k == "game":
                for attr_k, attr_v in v.items():
                    self.game[attr_k] = attr_v

        # 屏幕设置
        self.screen_width = int(self.screen["width"])
        self.screen_height = int(self.screen["height"])
        self.screen_bg_color = self.screen["bg_color"]

        # 飞船设置
        self.ship_speed_factor = int(self.ship["speed"])
        self.ship_limit = int(self.ship["limit"])

        # 子弹设置
        self.bullet_speed_factor = int(self.bullet["speed"])
        self.bullet_width = int(self.bullet["width"])
        self.bullet_height = int(self.bullet["height"])
        self.bullet_bg_color = self.bullet["bg_color"]
        self.bullet_allowed = int(self.bullet["allowed"])

        # 外星人设置
        self.alien_speed_factor = int(self.alien["speed"])
        self.alien_drop_speed = int(self.alien["drop_speed"])
        self.alien_fleet_direction = int(self.alien["fleet_direction"])
        self.alien_score_scale = int(self.alien["score_scale"])

        # 游戏速度
        self.speedup_scale = int(self.game["speedup_scale"])

        self.initialize_dynamic_settings()

    def initialize_dynamic_settings(self):
        """
        初始化随游戏进行而变化的设置
        """
        self.ship_speed_factor = int(self.ship["speed"])
        self.bullet_speed_factor = int(self.bullet["speed"])
        self.alien_speed_factor = int(self.alien["speed"])

        # alien_fleet_direction为1表示向右，为-1表示向左
        self.alien_fleet_direction = int(self.alien["fleet_direction"])

        # 每个外星人的分值
        self.alien_points = int(self.alien["points"])

    def increase_speed(self):
        """
        提到速度设置
        """
        self.ship_speed_factor *= self.speedup_scale
        self.bullet_speed_factor *= self.speedup_scale
        self.alien_speed_factor *= self.speedup_scale

        self.alien_points = int(self.alien_points * self.alien_score_scale)
